<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Deposite;
use App\Models\Enum\WithdrawalEnum;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;


class DepositeController extends BaseController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Deposite(['admin_user', 'admin_ids']), function (Grid $grid) {
            $grid = $this->gridButton($grid, true, false, false, true, true, true);

            $grid->model()->orderBy('id', 'desc');
            $grid->tableCollapse(false);
            $grid->responsive();

            $grid->id('编号')->sortable();
            $grid->column('admin_user.name', '姓名')->filter();
            $grid->column('admin_user.username', '交易帐号')->filter();
            $grid->usd_amount;
            $grid->column('type', '投入类型')->using(WithdrawalEnum::DEPOSTITE_TYPE)->label([
                1 => 'success', 2 => 'primary'
            ])->filter(Grid\Column\Filter\In::make(WithdrawalEnum::DEPOSTITE_TYPE));
            $grid->column('admin_ids.name', '操作人员');
            $grid->created_at->sortable();

            $grid->filter(function ($filter) {
                // 展开过滤器
                //$filter->expand();
                // 更改为 rightSide 布局
                $filter->panel();

                // 在这里添加字段过滤器
                $filter->like('admin_user.name', '姓名')->width(2);
                $filter->like('admin_user.username', '帐号')->width(2);
                $filter->whereBetween('created_at', function ($q) {
                    $start = $this->input['start'] ?? null;
                    $end   = $this->input['end'] ?? null;

                    $q->whereBetween('created_at', [$start, $end]);
                }, '日期')->date(1)->width(3);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param  mixed  $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return ;
        return Show::make($id, new Deposite(), function (Show $show) {
            $show->id;
            $show->user_id;
            $show->usd_amount;
            $show->tyep;
            $show->admin_id;
            $show->created_at;
            $show->updated_at;
        });
    }

    protected function del()
    {
        return ;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return ;
        return Form::make(new Deposite(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('usd_amount');
            $form->text('tyep');
            $form->text('admin_id');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
